package com.fare.taluo.core.domain.queue.warn;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

import com.fare.taluo.core.domain.analyse.alert.FreightPriceAnalyseAlertConfigEntity;
import com.fare.taluo.fetl.domain.entity.FreightPriceEntity;
import com.fare.taluo.util.DateUtils;

public class CompeteContrastWarnStrategy {
	private FreightPriceAnalyseAlertConfigEntity config;
	private List<FreightPriceEntity> list;
	public CompeteContrastWarnStrategy(
			FreightPriceAnalyseAlertConfigEntity config,List<FreightPriceEntity> list) {
		super();
		this.config = config;
		this.list = list;
	}
    
	public String buildEmailContent() {
		StringBuffer buffer = new StringBuffer();
		Integer trigger = config.getTriggerCondition();
		String upOrDown = null;
		if(trigger == 0){
			upOrDown = "低于";
		}else if(trigger == 1){
			upOrDown = "高于";
		}
		buffer.append(DateUtils.formatDay(config.getFlightDate(), "yyyy-MM-dd")+"起飞的<span style=\"color: #ff0000\">"+config.getFlightNo()+"</span>连续<span style=\"color: #ff0000\">"+config.getFutureDays()+"</span>天官网的");
		buffer.append("<span style=\"color: #ff0000\">"+config.getCabinLevel()+"</span>的最低价</span>连续<span style=\"color: #ff0000\">"+upOrDown+"</span>同天起飞的<span style=\"color: #ff0000\">"+config.getContrastFlightNo()+"</span>官网<span style=\"color: #ff0000\">"+config.getContrastCabinLevel()+"</span>最低价<br>");
		buffer.append("对应的记录是<br>");
		for (FreightPriceEntity entity : list) {
			buffer.append("抓取时间为:<span style=\"color: #ff0000\">"+DateUtils.formatDay(entity.getGrabDate(), "yyyy-MM-dd HH:mm")+"</span>的<span style=\"color: #ff0000\">"+entity.getGrabChannel()+"的"+entity.getFlightNo()+"</span>价格是<span style=\"color: #ff0000\">"+entity.getPrice()+"  </span>对应的<span style=\"color: #ff0000\">"+entity.getCompareGrabChannel()+
					"的"+entity.getCompareFlightNo()+"</span>的价格是<span style=\"color: #ff0000\">"+entity.getComparePrice()+"</span><br>");
		}
		return buffer.toString();
	}
	/*public static final int daysBetween(Date early, Date late) { 
	     
        java.util.Calendar calst = java.util.Calendar.getInstance();   
        java.util.Calendar caled = java.util.Calendar.getInstance();   
        calst.setTime(early);   
         caled.setTime(late);   
         //设置时间为0时   
         calst.set(java.util.Calendar.HOUR_OF_DAY, 0);   
         calst.set(java.util.Calendar.MINUTE, 0);   
         calst.set(java.util.Calendar.SECOND, 0);   
         caled.set(java.util.Calendar.HOUR_OF_DAY, 0);   
         caled.set(java.util.Calendar.MINUTE, 0);   
         caled.set(java.util.Calendar.SECOND, 0);   
        //得到两个日期相差的天数   
         int days = ((int) (caled.getTime().getTime() / 1000) - (int) (calst   
                .getTime().getTime() / 1000)) / 3600 / 24;   
         
        return days;   
   }   
  
   
   public static void main(String[] args)
   {
        Date earlydate = null;   
        Date latedate = null;   
        DateFormat df = DateFormat.getDateInstance();   
        try {   
            earlydate = df.parse("2009-09-21");   
            latedate = df.parse("2009-09-22");   
        } catch (ParseException e) {   
              e.printStackTrace();   
          }   
         int days = daysBetween(earlydate,latedate);   
         System.out.println(days);   
   }*/
	
	
	
}
